package bch.rocketmq.producer;

import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.message.Message;

@Slf4j
public class SyncProducer {
    public static void main(String[] args) {
        DefaultMQProducer producer = new DefaultMQProducer("business_group");
        producer.setNamesrvAddr("192.168.1.46:9876");
        try {
            producer.start();
            for (int i = 0; i < 10; i++) {
                String message = "Hello, RocketMQ " + i;
                SendResult send = producer.send(new Message("business_topic_1", "tag1", message.getBytes()));
                log.info("SendResult: {}", send);
            }
            producer.shutdown();
        } catch (Exception e) {
            log.error("Exception: ", e);
        }
    }
}
